﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using The_LarX;
using SynapseGaming.LightingSystem.Lights;
using Microsoft.Xna.Framework;
using SynapseGaming.LightingSystem.Shadows;
using SynapseGaming.LightingSystem.Rendering;
using System.Diagnostics;

namespace The_LarX
{
    public class SunBurnHDRSample : GameScreen
    {
        private Renderer_SunBurn Renderer;
        private FloatingCamera Camera;

        private Actor Actor;
        //private PointLight Point;
        //private PointLightSunBurn Pointy;
        private DirectionalLight DirLight;

        public SunBurnHDRSample()
        {
            Renderer = new Renderer_SunBurn();

            Camera = new FloatingCamera(Engine.AspectRatio, this);
            Camera.SetMousePosition = true;
            Renderer.Camera = Camera;

            Actor = new Actor("cena\\scene");

            // Post Processor
            Renderer.SceneInterface.PostProcessManager.AddPostProcessor(new HighDynamicRangePostProcessor(Engine.IGraphicsDeviceService));

            DirLight = new DirectionalLight();
            DirLight.Direction = new Vector3(-0.46f, -0.87f, -0.17f);
            DirLight.DiffuseColor = new Vector3(1.0f, 0.97f, 0.77f);
            DirLight.Intensity = 2;
            DirLight.ShadowType = ShadowType.AllObjects;
            DirLight.ShadowQuality = 1.0f;
            DirLight.ShadowPrimaryBias = 1.0f;
            DirLight.ShadowSecondaryBias = 0.04f;
        }

        public override void Update()
        {
            base.Update();

            Actor.Update();
            Renderer.Update();
        }

        public override void Draw()
        {
            base.Draw();

            Renderer.SubmitLight(DirLight);
            Renderer.SubmitActor(Actor);

            long startTime = Stopwatch.GetTimestamp();
            
            Renderer.RenderActors();
            
            long endTime = Stopwatch.GetTimestamp();
            double accumulatedPhysicsTime = (endTime - startTime) / (double)Stopwatch.Frequency;
            int finalTime = (int)(accumulatedPhysicsTime * 1000);
            Engine.RenderManager.DrawString("SunBurn:" + finalTime.ToString(),
              2, 200, new Vector2(100), "Kootenay", Color.White, null);
            Engine.RenderManager.DrawString("GameTime:" + Engine.GameTime.ElapsedGameTime.Milliseconds.ToString(),
                2, 200, new Vector2(100, 150), "Kootenay", Color.White, null);

            long gx = GC.GetTotalMemory(false);
            long final = gx / 1024;
            Engine.RenderManager.DrawString(final.ToString(), 2, 200, new Vector2(100, 200), "Kootenay", Color.White,
                null);
        }
    }
}